package com.nanhai.buddhist.college.module.collegebase.dal.mysql.accommodationreside;

import java.util.*;

import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.nanhai.buddhist.college.framework.mybatis.core.mapper.BaseMapperX;
import com.nanhai.buddhist.college.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.accommodationbed.AccommodationBedDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.accommodationreside.AccommodationResideDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.accommodationroom.AccommodationRoomDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.colleges.CollegesDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.departments.DepartmentsDO;
import org.apache.ibatis.annotations.Mapper;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.accommodationreside.vo.*;

/**
 * 入住记录 Mapper
 *
 * @author 南海佛学院
 */
@Mapper
public interface AccommodationResideMapper extends BaseMapperX<AccommodationResideDO> {
    default PageResult<AccommodationResideDO> selectPage(AccommodationResidePageReqVO reqVO) {
        return selectPageForJoin(reqVO,AccommodationResideDO.class, new MPJLambdaWrapperX<AccommodationResideDO>()
                .eqIfPresent(AccommodationResideDO::getRole, reqVO.getRole())
                .likeIfPresent(AccommodationResideDO::getResideName, reqVO.getResideName())
                .eqIfPresent(AccommodationResideDO::getBedId, reqVO.getBedId())
                .eqIfPresent(AccommodationResideDO::getCollegeId, reqVO.getCollegeId())
                .eqIfPresent(AccommodationRoomDO::getDepartmentId,reqVO.getDepartmentId())
                .eqIfPresent(AccommodationRoomDO::getId,reqVO.getRoomId())
                .eqIfPresent(AccommodationResideDO::getResideStatus,reqVO.getResideStatus())
                .likeIfPresent(AccommodationRoomDO::getRoomName,reqVO.getRoomName())
                .leftJoin(AccommodationBedDO.class,AccommodationBedDO::getId,AccommodationResideDO::getBedId)
                .leftJoin(AccommodationRoomDO.class,AccommodationRoomDO::getId,AccommodationBedDO::getRoomId)
                .leftJoin(DepartmentsDO.class,DepartmentsDO::getId,AccommodationRoomDO::getDepartmentId)
                .leftJoin(CollegesDO.class,CollegesDO::getId,DepartmentsDO::getCollegeId)
                .selectAll(AccommodationResideDO.class)
                .selectAs(AccommodationBedDO::getBedName,AccommodationResideDO::getBedName)
                .selectAs(AccommodationRoomDO::getRoomName,AccommodationResideDO::getRoomName)
                .selectAs(DepartmentsDO::getDepartmentName,AccommodationResideDO::getDepartmentName)
                .selectAs(CollegesDO::getCollegeName,AccommodationResideDO::getCollegeName)
                .orderByDesc(AccommodationResideDO::getCreateTime));
    }

    default List<AccommodationResideDO> selectList(AccommodationResideExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<AccommodationResideDO>()
                .eqIfPresent(AccommodationResideDO::getRole, reqVO.getRole())
                .likeIfPresent(AccommodationResideDO::getResideName, reqVO.getResideName())
                .eqIfPresent(AccommodationResideDO::getBedId, reqVO.getBedId())
                .eqIfPresent(AccommodationResideDO::getCollegeId, reqVO.getCollegeId())
                .orderByDesc(AccommodationResideDO::getCreateTime));
    }

}
